import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_woo_new/global.dart';
import 'package:get/route_manager.dart';

import 'common/index.dart';

void main() async {
  await Global.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // 这个部件是应用程序的根部件。
  @override
  Widget build(BuildContext context) {
    return AdaptiveTheme(
      // 样式
      light: AppTheme.light, // 浅色主题
      dark: AppTheme.dark, // 深色主题
      initial: ConfigService.to.themeMode, // 初始主题
      debugShowFloatingThemeButton: true, // 调试显示切换主题按钮

      // 构建
      builder: (theme, darkTheme) => GetMaterialApp(
        // 标题
        title: 'Flutter 示例',
        // 主题
        theme: theme, // 浅色主题
        darkTheme: darkTheme, // 深色主题
        //多语言
        translations: Translation(), //词典
        localizationsDelegates: Translation.localizationsDelegates, //代理
        supportedLocales: Translation.supportedLocales, //支持的语言种类
        locale: ConfigService.to.locale, //当前语言
        fallbackLocale: Translation.fallbackLocale, //默认语言
        // 路由
        initialRoute: RouteNames.stylesStylesIndex,
        getPages: RoutePages.list,
        navigatorObservers: [RoutePages.observers],
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              '你已经按下按钮这么多次了：',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: '增加',
        child: const Icon(Icons.add),
      ), // 这个尾随逗号使 build 方法的自动格式化更美观。
    );
  }
}
